package com.hd.trans.widgets

import android.content.Context
import android.view.LayoutInflater
import androidx.recyclerview.widget.LinearLayoutManager
import com.hd.trans.R
import com.hd.trans.databinding.DialogAlbumTransBinding
import com.hd.trans.files.bean.Album
import com.hd.trans.files.bean.MediaOptions

/**
 * @author       qianjujun
 * @email        qianjujun@163.com
 * @createTime  2021/1/5 17:40
 * @describe
 */
class AlbumDialog(context: Context, private val options: MediaOptions) : MyDialog<DialogAlbumTransBinding>(
    context, LayoutInflater.from(context).inflate(R.layout.dialog_album_trans, null)
) {

    private var mAlbumVm: AlbumAdapter

    private var callback: ((album: Album) -> Unit)? = null

    private var showCallback: ((show: Boolean) -> Unit)? = null


    fun setCallback(callback: (album: Album) -> Unit) {
        this.callback = callback
    }

    fun setShowCallback(showCallback: (show: Boolean) -> Unit) {
        this.showCallback = showCallback
    }


    init {
        // height = ViewGroup.LayoutParams.WRAP_CONTENT
        mDataBinding.recyclerView.layoutManager = LinearLayoutManager(mContext)
        mAlbumVm = AlbumAdapter(options)
        mDataBinding.recyclerView.adapter = mAlbumVm

        mAlbumVm.setOnModuleItemClickListener { _, t, dataPosition ->
            run {
                callback?.invoke(t)
                mAlbumVm.selectItem(dataPosition)
                dismiss()
            }
        }

        dialog.setOnDismissListener {
            showCallback?.invoke(false)
        }


    }

    fun setData(albumList: List<Album>?) {
        mAlbumVm.setList(albumList ?: ArrayList())
    }


    override fun showFromBottom() {
        showCallback?.invoke(true)
        super.showFromBottom()
    }

}




